include:
    {% if pillar['nginx_version'] == "tengine" %}
    - prod.nginx.tengine_install
    {% endif %}
    {% if pillar['nginx_version'] == "openresty" %}
    - prod.nginx.openresty_install
    {% endif %}

nginx-init:
    file.managed:
        - name: /etc/init.d/nginx
        - source: salt://prod/nginx/files/nginx-init
        - unless: test -f /etc/init.d/nginx
        - mode: 755
        - user: root
        - group: root

    cmd.run:
        - name: chkconfig --add nginx
        - unless: chkconfig --list |grep nginx
        - require:
            - file: nginx-init

/usr/local/nginx/conf/nginx.conf:
    file.managed:
        - source: salt://prod/nginx/files/nginx.conf
        - user: ecp
        - group: ecp
        - mode: 644
        - template: jinja
        - defaults:
            nginx_user: ecp
            defaults_port: 8080
            num_cpus: {{ grains['num_cpus'] }}
    cmd.run:
        - name: ldconfig

nginx-service:
    file.directory:
        - name: /usr/local/nginx/conf/vhost
        - require:
            - cmd: nginx-source-install

    service.running:
        - name: nginx
        - enable: True
        - reload: True
        - require:
            - cmd: nginx-init
        - watch:
            - file: /usr/local/nginx/conf/nginx.conf    
